<style lang="less">
.vertical-center-modal {
  .ivu-modal {
    margin-top: 10%;
  }
}
</style>
<template>
  <div>

    <Form ref="formValidate" :model="tempData" :label-width="70" :rules="ruleValidate">
      <FormItem label="名称" prop="Name">
        <Input v-model="tempData.Name" />
      </FormItem>
      <FormItem label="手机号" prop="Phone">
        <Input v-model="tempData.Phone" />
      </FormItem>
      <FormItem v-if="Id == 0" label="期初账目" prop="Balance">
        <Input type="number" v-model="tempData.Balance">
        <span slot="append">元</span>
        </Input>
        <div style="padding-top:5px">
          <Tag type="dot" color="error" size="large"><span style="font-size:14px">正数为预付款，负数为欠款（如：张三欠我5000元，则录入-5000）</span> </Tag>
        </div>
      </FormItem>
      <FormItem label="地址" prop="Address">
        <Input type="textarea" v-model="tempData.Address" />
      </FormItem>
      <FormItem label="备注" prop="Remark">
        <Input type="textarea" v-model="tempData.Remark" />
      </FormItem>
    </Form>
    <div class="div-footer">
      <Button type="text" @click="cancel()">取消</Button>
      <Button type="primary" :loading="loading" @click="SaveCustomer">确定</Button>
    </div>
  </div>
</template>

<script>

import { GetCustomer, SaveCustomer } from '@/api/customer'

export default {
  name: 'customeredit',
  props: ['Id'],
  data () {
    return {

      ruleValidate: {
        Name: [
          {
            required: true,
            message: '不能为空',
            trigger: 'blur'
          }
        ]

      },
      loading: false,
      tempData: {
        Name: ''
      }

    }
  },

  computed: {},

  methods: {
    cancel () {
      this.$emit('on-success', 0)
    },
    GetCustomer () {
      let vm = this
      GetCustomer(vm.Id).then((res) => {
        var data = res.data
        if (data.StatusCode == 200) {
          vm.tempData = data.Data
        } else {
          vm.$Notice.error({
            title: data.Errors
          })
        }
      })
    },
    SaveCustomer () {
      let vm = this
      vm.$refs['formValidate'].validate((valid) => {
        if (valid) {
          vm.loading = true
          SaveCustomer(vm.tempData).then((res) => {
            vm.loading = false
            const data = res.data
            if (data.StatusCode == 200) {
              vm.$Message.success({ title: '提示', content: '保存成功' })
              vm.$emit('on-success', 1)
            } else {
              vm.$Message.error({ title: '提示', content: data.Errors })
            }
          })
        }
      })
    }

  },
  mounted () {
    if (this.Id > 0) {
      this.GetCustomer()
    }
  }
}
</script>

<style>
</style>
